package job;

import java.util.Timer;
import java.util.TimerTask;

import job.Producer.Topic;
import play.Logger;
import service.impl.ErrorTicketMessageQueue;
import service.impl.FullReturnSchedulePriceMessageQueue;
import service.impl.InsuranceMessageQueue;
import service.impl.LossTicketsMessageQueue;
import service.impl.NetOrganizationMessageQueue;
import service.impl.OutletsinfoMessageQueue;
import service.impl.PayRecordsMessageQueue;
import service.impl.QHStationDataMessageQueue;
import service.impl.ScheduleCancelMessageQueue;
import service.impl.SchedulePriceDelMessageQueue;
import service.impl.SchedulePriceMessageQueue;
import service.impl.SelfSaleTicketMessageQueue;
import service.impl.StationMessageQueue;
import service.impl.StationSendsMessageQueue;
import service.impl.StationWebTicketMessageQueue;
import service.impl.StationbehindscheduleMessageQueue;
import service.impl.StationinsuranceMessageQueue;
import service.impl.StationstaffMessageQueue;
import service.impl.StationviewgpsMessageQueue;
import service.impl.TicketSellMessageQueue;
import service.impl.TicketsourcesMessageQueue;
import service.impl.UpdateExchangefeeMessageQueue;
import service.impl.VehicleMessageQueue;
import utils.LogUtil;
import utils.SystemParam;

public class ConsumerTimer {
	
	//Date time = new Date();
	Timer timer = new Timer(false);
	TimerTask schedulepricetask = null;
	private static ConsumerTimer consumertimer;
	
	private ConsumerTimer(){
		
	}
	public static synchronized ConsumerTimer getInstanse(){
		if(consumertimer==null){
			consumertimer = new ConsumerTimer();
		}
		return consumertimer;
	}
	
	public  void  monitorSynprocess(Topic topic){
		switch (topic.ordinal()) {
		case 0:
			TimerTask stationtask = new TimerTask() {//站点
				@Override
				public void run() {
					Logger.log4j.info("站点消息消费....");
					StationMessageQueue staitonqueue = StationMessageQueue.getInstance();
					try {
						if(StationMessageQueue.canwork())
							staitonqueue.consumeMessages(2);
						//this.cancel();
					} catch (Exception e) {
						
						e.printStackTrace();
						LogUtil.logerror("monitorSynprocess 站点消费批量消息失败", e);
					}
				}
			};
			timer.schedule(stationtask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);//task, delay-延迟执行, period--间隔
			break;
		case 1:
			TimerTask schedulepricetask = new TimerTask() {//班次计划
				@Override
				public void run() {
					Logger.log4j.info("班次数据消费....");
					SchedulePriceMessageQueue schedulequeue = SchedulePriceMessageQueue.getInstance();
					try {
						if(SchedulePriceMessageQueue.canwork())
							schedulequeue.consumeMessages(2);
					} catch (Exception e) {
						e.printStackTrace();
						LogUtil.logerror("monitorSynprocess 班次数据消费批量消息失败", e);
					}
				}
			};
			timer.schedule(schedulepricetask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 2:
			TimerTask tickettask = new TimerTask() {//车票
				@Override
				public void run() {
					Logger.log4j.info("车票信息消费....");
					TicketSellMessageQueue ticketqueue = TicketSellMessageQueue.getInstance();
					try {
						if(TicketSellMessageQueue.canwork())
							ticketqueue.consumeMessages(2);
					} catch (Exception e) {
						e.printStackTrace();
						LogUtil.logerror("monitorSynprocess 车票消费批量消息失败", e);
					}
				}
			};
			timer.schedule(tickettask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 3:
			TimerTask pricedeltask = new TimerTask() {//班次删除
				@Override
				public void run() {
					Logger.log4j.info("删除班次信息消费....");
					SchedulePriceDelMessageQueue pricedelqueue = 
							SchedulePriceDelMessageQueue.getInstance();
					try {
						if(SchedulePriceDelMessageQueue.canwork())
							pricedelqueue.consumeMessages(2);
					} catch (Exception e) {
						e.printStackTrace();
						LogUtil.logerror("monitorSynprocess 删除班次消息消费失败", e);
					}
				}
			};
			timer.schedule(pricedeltask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 4:
			TimerTask vehicletask = new TimerTask() {//车牌
				@Override
				public void run() {
					Logger.log4j.info("车牌消息消费....");
					VehicleMessageQueue vehiclequeue = VehicleMessageQueue.getInstance();
					try {
						if(VehicleMessageQueue.canwork())
							vehiclequeue.consumeMessages(2);
					} catch (Exception e) {
						e.printStackTrace();
						LogUtil.logerror("monitorSynprocess 车牌消息消费失败", e);
					}
					
				}
			};
			timer.schedule(vehicletask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 5:
			break;
		case 6:
			break;
		case 7:
			TimerTask errortickettask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("取票异常消息消费....");
					ErrorTicketMessageQueue errorticketqueue = 
							ErrorTicketMessageQueue.getInstance();
					try {
						if(ErrorTicketMessageQueue.canwork())
							errorticketqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(errortickettask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 8:
			TimerTask selfsaletickettask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("自助售票车票消息消费....");
					SelfSaleTicketMessageQueue selfsaleticketqueue = 
							SelfSaleTicketMessageQueue.getInstance();
					try {
						if(SelfSaleTicketMessageQueue.canwork())
							selfsaleticketqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(selfsaletickettask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 9:
			TimerTask updateexchangefeetask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("更新手续费消息消费....");
					UpdateExchangefeeMessageQueue selfsaleticketqueue = 
							UpdateExchangefeeMessageQueue.getInstance();
					try {
						if(UpdateExchangefeeMessageQueue.canwork())
							selfsaleticketqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(updateexchangefeetask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 10:
			TimerTask ticketsourcestask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车票数据来源信息消息消费....");
					TicketsourcesMessageQueue ticketsourcesqueue = 
							TicketsourcesMessageQueue.getInstance();
					try {
						ticketsourcesqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(ticketsourcestask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 11:
			TimerTask stationstafftask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站员工数据信息消息消费....");
					StationstaffMessageQueue stationstaffqueue = 
							StationstaffMessageQueue.getInstance();
					try {
						stationstaffqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(stationstafftask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 12:
			TimerTask outletsinfotask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站代售点信息消息消费....");
					OutletsinfoMessageQueue outletsinfoqueue = 
							OutletsinfoMessageQueue.getInstance();
					try {
						outletsinfoqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(outletsinfotask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 13:
			TimerTask behindtask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站脱班信息消息消费....");
					StationbehindscheduleMessageQueue behindqueue = 
							StationbehindscheduleMessageQueue.getInstance();
					try {
						behindqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(behindtask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 14:
			TimerTask stationsendstask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站发送旅客信息消息消费....");
					StationSendsMessageQueue sendsqueue = 
							StationSendsMessageQueue.getInstance();
					try {
						sendsqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(stationsendstask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 15:
			TimerTask payrecordtask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("自助机支付信息消息消费....");
					PayRecordsMessageQueue sendsqueue = 
							PayRecordsMessageQueue.getInstance();
					try {
						sendsqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(payrecordtask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 16:
			TimerTask fullreturnscheduletask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("可全额退票班次信息消息消费....");
					FullReturnSchedulePriceMessageQueue sendsqueue = 
							FullReturnSchedulePriceMessageQueue.getInstance();
					try {
						sendsqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(fullreturnscheduletask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 17:
			TimerTask losstickettask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("错误车票票证信息消息消费....");
					LossTicketsMessageQueue sendsqueue = 
							LossTicketsMessageQueue.getInstance();
					try {
						sendsqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(losstickettask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 18:
			TimerTask stationinsurancetask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站保险信息消息消费....");
					StationinsuranceMessageQueue sendsqueue = 
							StationinsuranceMessageQueue.getInstance();
					try {
						sendsqueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(stationinsurancetask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 19:
			TimerTask netorganizationstask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("中心机构信息消息消费....");
					NetOrganizationMessageQueue netOrganizationMessageQueue = 
							NetOrganizationMessageQueue.getInstance();
					try {
						netOrganizationMessageQueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(netorganizationstask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 20:
			TimerTask stationviewgpstask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站GPS车辆监管消息消费....");
					StationviewgpsMessageQueue stationviewgpsMessageQueue = 
							StationviewgpsMessageQueue.getInstance();
					try {
						stationviewgpsMessageQueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(stationviewgpstask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 21:
			TimerTask QHStationDatastask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("青海车站发班运量消息消费....");
					QHStationDataMessageQueue stationviewgpsMessageQueue = 
							QHStationDataMessageQueue.getInstance();
					try {
						stationviewgpsMessageQueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(QHStationDatastask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 22:
			TimerTask InsuranceDatastask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("保险消息消费....");
					InsuranceMessageQueue stationviewgpsMessageQueue = 
							InsuranceMessageQueue.getInstance();
					try {
						stationviewgpsMessageQueue.consumeMessages(2);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			timer.schedule(InsuranceDatastask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 23:
			TimerTask schedulecanceltask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("雪天停运可全额退票停班信息消息消费....");
					ScheduleCancelMessageQueue schedulecancelqueue = 
							ScheduleCancelMessageQueue.getInstance();
					try {
						schedulecancelqueue.consumeMessages(2);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			};
			timer.schedule(schedulecanceltask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		case 24:
			TimerTask stationwebtickettask = new TimerTask() {
				@Override
				public void run() {
					Logger.log4j.info("车站窗口收单数据信息消息消费....");
					StationWebTicketMessageQueue schedulecancelqueue = 
							StationWebTicketMessageQueue.getInstance();
					try {
						schedulecancelqueue.consumeMessages(2);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			};
			timer.schedule(stationwebtickettask,SystemParam.MONITOR_CONSUMER_DELAY*1000, SystemParam.MONITOR_CONSUMER_PERIOD*1000);
			break;
		default:
			break;
		}
				
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ConsumerTimer timer = ConsumerTimer.getInstanse();
		timer.monitorSynprocess(Topic.Station);
		timer.monitorSynprocess(Topic.SchedulePrice);
		timer.monitorSynprocess(Topic.Ticket);
		
	}

}
